using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.ComponentModel;
using System.Web.UI;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using IWCommunity.Blogs.WebControls;

namespace IWCommunity.WebControls
{
    [ToolboxData("<{0}:SiteTagsWebPart runat=server></{0}:SiteTagsWebPart>")]
    [XmlRoot(Namespace = "IWCommunity.WebControls")]
    public class SiteTagsWebPart : Microsoft.SharePoint.WebPartPages.WebPart
    {
        protected override void CreateChildControls()
        {
            SiteTags tags = new SiteTags();
            tags.ID = "stags";
            tags.Transform.XslName = XslFileName;
            tags.TagXmlFileUrl = TagsXmlFilePath;
            tags.CacheTimeout = _cacheTimeout;
            tags.EnableCaching = _enableCache;
            tags.CacheDebug = _enableCacheDebug;

            //if (TagResultPage.Length > 0)
            //    tags.TagPageURL = TagResultPage;

            this.Controls.Add(tags);

        }

        private string _xslFileName;
        [Browsable(true), Category("Miscellaneous"), WebPartStorage(Storage.Shared), FriendlyName("XSL File Name"), Description("Name of the file to use for XSTL tranformation")]
        public string XslFileName
        {
            get
            {
                return _xslFileName;
            }

            set
            {
                _xslFileName = value;
            }
        }

        //private string _tagResultPage = string.Empty;
        //[Browsable(true), Category("Miscellaneous"), WebPartStorage(Storage.Shared), FriendlyName("Page to send on tag click"), Description("Path of page to goto when clicked a tag")]
        //public string TagResultPage
        //{
        //    get
        //    {
        //        return _tagResultPage;
        //    }

        //    set
        //    {
        //        _tagResultPage = value;
        //    }
        //}

        private string _tagsXmlFilePath;
        [Browsable(true), Category("Miscellaneous"), WebPartStorage(Storage.Shared), FriendlyName("Tags XML File Path"), Description("Http path to XML file for source of tags")]
        public string TagsXmlFilePath
        {
            get
            {
                return _tagsXmlFilePath;
            }

            set
            {
                _tagsXmlFilePath = value;
            }
        }

        private int _cacheTimeout;
        [Browsable(true), Category("Miscellaneous"), WebPartStorage(Storage.Shared), FriendlyName("Cache Timeout"), Description("How long to cache (mins) the result HTML for")]
        public int CacheTimeout
        {
            get
            {
                return _cacheTimeout;
            }

            set
            {
                _cacheTimeout = value;
            }
        }

        private bool _enableCache;
        [Browsable(true), Category("Miscellaneous"), WebPartStorage(Storage.Shared), FriendlyName("Enable Cache"), Description("Set to true to enable caching of the html")]
        public bool EnableCache
        {
            get
            {
                return _enableCache;
            }

            set
            {
                _enableCache = value;
            }
        }

        private bool _enableCacheDebug = false;
        [Browsable(true), Category("Miscellaneous"), WebPartStorage(Storage.Shared), FriendlyName("Show Cache Debug"), Description("Adds date and time rendered to part")]
        public bool EnableCacheDebug
        {
            get
            {
                return _enableCacheDebug;
            }

            set
            {
                _enableCacheDebug = value;
            }
        }
    }
}
